<?php
class Model_Menu extends Zend_Db_Table_Abstract{
	protected  $_name = 'menu';
	public function getAllMenus(){
		return $this->fetchAll($this->select()->order('priority'));
	}
	public function getMenuByID($id){
		return $this->find($id)->current();
	}
	public function createMenu($name, $link, $priority){
		$menu = $this->createRow();
		$menu->name = $name;
		$menu->link = $link;
		$menu->priority = $priority;
		$menu->save();
		return $this->_db->lastInsertId();
	}
	public function updateMenu($id, $name, $link, $priority){
		$data = array('name' => $name, 'link' => $link, 'priority' => $priority);
		try{
			$this->update($data,'id='.$id);
			return true;
		}catch (Exception $ex){
			echo "Caught exception: " + $ex->getMessage();
			return false;
		}
	}
	public function deleteMenu($id){
		if(is_numeric($id)){
			return $this->delete('id = '.$id);
		}else{
			return $this->delete('id in ('.$id.')');
		}
	}
	
}